import { defineStore } from "pinia";
import { type Music_doc } from "@/types/Music"
import { Add_doc, Get_list, Music_put, MuSIC_dele } from "@/apis/MusicApi"
import { ElMessage } from "element-plus";
const MusicStore = defineStore('music', () => {
    //添加
    const add_doc = async (data: Music_doc) => {
        const result: any = await Add_doc(data)
        console.log(result)
        if (result.code = 200) {
            ElMessage({
                type: "success",
                message: "添加成功"
            })
        } else {
            ElMessage({
                type: "error",
                message: "添加失败"
            })
        }
    }
    //获取列表
    const Get_Music_list = async (id: number) => {
        const result: any = await Get_list(id)
        if (result.code == 200) {
            return {
                data: result.data,
                count: result.count
            }
        } else {
            return {
                data: [],
                count: 0
            }
        }
    }
    //修改
    const Put_music = async (data: Music_doc) => {
        const result: any = await Music_put(data)
        if (result.code = 200) {
            ElMessage({
                type: "success",
                message: "修改成功"
            })
        } else {
            ElMessage({
                type: "success",
                message: "修改失败"
            })
        }
    }
    //删除
    const Delete_music = async (id: string) => {
        const result: any = await MuSIC_dele(id)
        if (result.code = 200) {
            ElMessage({
                type: "success",
                message: "删除成功"
            })
        } else {
            ElMessage({
                type: "error",
                message: "删除失败"
            })
        }
    }
    return {
        add_doc,
        Get_Music_list,
        Put_music,
        Delete_music
    }
})


export default MusicStore